//
//  ChooseStateViewController.m
//  Memo
//
//  Created by A-01 on 2020/7/10.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "ChooseStateViewController.h"
#import "StateTableViewCell.h"

@interface ChooseStateViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UITableView * tableView;
@property (nonatomic, strong)NSArray * imgArray;
@property (nonatomic, strong)NSArray * titleArray;

@end

@implementation ChooseStateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text = @"State List";
    
    [self setupUI];
}


- (void)setupUI{

    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavHeight + 20, kScreenW, self.view.height - kNavHeight + 20) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor clearColor];
    tableView.rowHeight = 75;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    self.tableView = tableView;
       
    [self.tableView registerClass:[StateTableViewCell class] forCellReuseIdentifier:@"StateTableViewCell"];
       
    [self.view addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 6;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.returnState(self.titleArray[indexPath.row]);
    [self.navigationController popViewControllerAnimated:YES];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    StateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StateTableViewCell" forIndexPath:indexPath];
        
    cell.stateLabel.text = self.titleArray[indexPath.row];
    cell.stateImageView.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
    
    return cell;
}

-(void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
}

-(NSArray *)imgArray{
    
    if (!_imgArray) {
        
        _imgArray = @[@"processing",@"processing",@"notstarted",@"expired",@"unlimited",@"notunlimited"];
    }
    
    return _imgArray;
}


-(NSArray *)titleArray{
    
    if (!_titleArray) {
        
        _titleArray = @[@"completed",@"processing",@"not yet started",@"expired",@"unlimited,processing",@"unlimited,not yet started"];
    }
    
    return _titleArray;
}


-(void) returnState:(stateBlock)block
{
    self.returnState = block;
}

@end
